package com.mspbots.core.ticketai;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mspbots.core.ticketai.model.BoardOnly;
import com.mspbots.core.ticketai.model.Priority;
import com.mspbots.core.ticketai.service.BoardService;
import com.mspbots.core.ticketai.service.PriorityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * com.mspbots.sync.wise.controller.BoardController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/11/13
 */
@Log4j2
@RestController
@RequiredArgsConstructor
@RequestMapping("boards")
public class BoardController {

    private final BoardService boardService;
    private final PriorityService priorityService;

    @GetMapping("all")
    public Callable<List<BoardOnly>> getBards(@RequestParam Long tenantId, @RequestParam(required = false) Long cwUid) {
        Assert.notNull(tenantId, "Query params tenantId not null");
        return () -> this.boardService.getListOnly(tenantId, cwUid);
    }

    @GetMapping("priorities")
    public Callable<List<Priority>> getPriorities(@RequestParam Long tenantId) {
        Assert.notNull(tenantId, "Query params tenantId not null");
        return () -> this.priorityService.list(Wrappers.<Priority>lambdaQuery().eq(Priority::getTenantId, tenantId)
                .orderByAsc(Priority::getCwId));
    }


    @GetMapping("getBoardByTimeEntry")
    public Callable getBoardByTimeEntry(@RequestParam Long tenantId, @RequestParam Long chargeToId) {
        Assert.notNull(tenantId, "Query params tenantId not null");
        Assert.notNull(chargeToId, "Query params tenantId not null");
        return () -> this.boardService.getBoardByTimeEntry(tenantId, chargeToId);
    }


}
